home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-04-16 | 1.1 KB | 51 lines | [TEXT/CWIE] |
- // PowerPlantMutex.cp
- // Copyright: © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
-
-
- #include "PowerPlantMutex.h"
- #include <LMutexSemaphore.h>
- #include <LThread.h>
- #include <UException.h>
- #include <UThread.h>
-
- class PowerPlantMutex : public IAMutex, public LMutexSemaphore {
- public:
- void Lock();
- void Unlock();
- void Signal();
- };
-
- IAMutex* NewPowerPlantMutex() {
- return new PowerPlantMutex();
- }
-
- void PowerPlantMutex::Lock() {
- ThrowIfOSErr_(Wait());
- }
-
- void PowerPlantMutex::Unlock() {
- Signal();
- }
-
- void PowerPlantMutex::Signal() {
- // code copied from LMutexSemaphor::Signal(), except w/o call to LThread::Yield()
- LThread *thread = LThread::GetCurrentThread();
- {
- StCritical critical; // disable preemption within this block
- if (thread != mOwner) {
- Throw_(errSemaphoreNotOwner);
- } else if (mNestedWaits > 0) {
- --mNestedWaits;
- } else if (mExcessSignals < 0) {
- THREAD_ASSERT(mThreads.qHead != NULL);
- mOwner = UnblockThread(mThreads.qHead, noErr);
- } else {
- THREAD_ASSERT(mExcessSignals == 0);
- mOwner = NULL;
- ++mExcessSignals;
- }
- }
- //LThread::Yield();
- }
-
-